package Ali;

import javax.security.auth.login.AccountException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    static long mod=1000000000+7;
    static long getnum(String line,int i){
        long res=0;
        int ca=1;
        for (int j = line.length()-1; j >= 0; j--) {
            char c=line.charAt(j);
            if (c>='A'&&c<='F'){
                res+=(ca*(c-'A'+10)%mod);
                ca*=i;
                continue;
            }
            if (c>='0'&&c<='9'){
                res+=(ca*(c-'0'))%mod;
                ca*=i;
                continue;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner ci=new Scanner(System.in);
        String n=ci.nextLine();
        char[] chars = n.toCharArray();
        int start=2;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i]>='A'||chars[i]<='F'){
                start=Math.max((chars[i]-'A')+11,start);
            }
            if (chars[i]>='0'&&chars[i]<='9'){
                start=Math.max(chars[i]-'0',start);
            }
        }
        ArrayList<Long> res=new ArrayList<>();
        for (int i = start; i <= 16; i++) {
            long num=getnum(n,i);
            if (!res.contains(num)){
                res.add(num);
            }
        }
        Collections.sort(res);
        for (int i = 0; i < res.size(); i++) {
            System.out.println(res.get(i));
        }
    }
}
